const machineService = require('../service/machine');
const modulePath = 'machine';
module.exports = app => {
  app.get(`/${modulePath}/info`, (req, res) => {
    const { id } = req.query;
    machineService.getMachine(data => {
      res.send(JSON.stringify({
        success: true,
        code: 100,
        data: data
      }))
    })
  })
  app.get(`/${modulePath}/run`, (req, res) => {
    const { id } = req.query;
    machineService.setStatus('启动中', (err) => {
      if(!err){
        res.send(JSON.stringify({
          success: true,
          code: 100,
          data: '启动中'
        }))
        machineService.startMachine();
      }
    })
  })
  app.get(`/${modulePath}/stop`, (req, res) => {
    const { id } = req.query;
    machineService.setStatus('停止中', (err) => {
      if(!err){
        res.send(JSON.stringify({
          success: true,
          code: 100,
          data: '停止中'
        }))
        machineService.stopMachine();
      }
    })
  })
}